const { backendApiUrl } = require('../../utils/config');
import { apiRequest } from '../_utils/apiRequest';

/**
 * 获取VIP会员子用户列表
 * @param {string} userId - 用户 ID
 * @returns {Promise} - 返回子用户列表的 Promise
 */
const getMemberSubs = (userId) => {
  return apiRequest({
    url: `${backendApiUrl}/users/me/subs`,
    method: 'GET',
  });
};

/**
 * 删除VIP会员
 * @param {string} memberId - VIP会员 ID
 * @returns {Promise} - 返回一个成功或失败的 Promise
 */
const deleteMember = (memberId) => {
  return apiRequest({
    url: `${backendApiUrl}/users/${memberId}`,
    method: 'DELETE',
  });
};

/**
 * 更新VIP会员为游客
 * @param {string} memberId - VIP会员 ID
 * @returns {Promise} - 返回一个成功或失败的 Promise
 */
const updateMemberToGuest = (memberId) => {
  return apiRequest({
    url: `${backendApiUrl}/users/${memberId}`,
    method: 'PUT',
    data: {
      role: 'GUEST',
      parentId: null
    }
  });
};

module.exports = {
  getMemberSubs,
  deleteMember,
  updateMemberToGuest,
};
